<template>
  <!-- 合同审核 -->
  <el-dialog
    v-el-drag-dialog
    title="合同审核"
    :visible.sync="visible"
    width="50%"
    append-to-body
    @close="reset"
  >
    <div slot="footer" class="dialog-footer">
      <el-button @click="reset">
        关闭
      </el-button>
      <el-button v-if="isBtn" type="primary" @click="pass">
        通过
      </el-button>
      <el-button v-if="isBtn" type="primary" @click="cancellation">
        作废
      </el-button>
    </div>
    <div v-html="content" />
    <cancellation-cause ref="cancellationCause" @upChange="upChange" />
  </el-dialog>
</template>

<script>
  import { queryEableContractTempWin, queryEableContractCheck } from '@/api'
  import CancellationCause from './CancellationCause'

  export default {
    name: 'audit-confirm',
    components: {
      CancellationCause
    },
    data() {
      return {
        visible: false,
        content: '',
        isBtn: true,
        row: {}
      }
    },
    methods: {
      async open(row) {
        console.log('row', row)
        this.row = row
        const res = await queryEableContractTempWin({
          templateId: row.templateId,
          contractId: row.contractId
        })
        this.content = res.data.content
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
        })
      },
      // 作废
      cancellation() {
        console.log('作废')
        this.$refs.cancellationCause.open()
      },
      // 通过
      pass() {
        this.$confirm(`确定审核通过此合同?`, '提示', {
          type: 'info'
        }).then(async() => {
          const { status } = await queryEableContractCheck({
            templateId: this.row.templateId,
            contractId: this.row.contractId
          })
          console.log('通过', status)
          if (status === 200) {
            this.$notify({
              title: '提示',
              message: '审核成功!',
              type: 'success',
              duration: 2000
            })
            this.isBtn = false
            this.$emit('upDataTable')
          }
        })
      },
      // 更新按钮状态
      upChange() {
        this.isBtn = false
        this.$emit('upDataTable')
      },
      // 详情
      reset() {
        this.visible = false
        this.isBtn = true
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
